package com.ruoyi.mobile.project.ums.service;

import com.github.pagehelper.PageHelper;
import com.ruoyi.db.ums.domain.UmsFootprint;
import com.ruoyi.db.ums.domain.query.UmsFootprintQueryVo;
import com.ruoyi.db.ums.mapper.UmsFootprintMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class WxUmsFootprintService
{
    @Autowired
    private UmsFootprintMapper footprintMapper;

    /**
     * 毛思淼  通过添加时间查找
     * @param userId
     * @param page
     * @param size
     * @return
     */
    public List<UmsFootprint> queryByAddTime(Long userId, Integer page, Integer size)
    {

        //开始分页
        PageHelper.startPage(page, size);
        //建立一个浏览对象实体
        UmsFootprintQueryVo footprintQueryVo = new UmsFootprintQueryVo();
        //给该实体赋值userId确定是哪个用户的
        footprintQueryVo.setUserId(userId);
        //查找该用户的所有浏览足迹对象
        return footprintMapper.selectUmsFootprintList(footprintQueryVo);

    }

    public UmsFootprint findById(Long id)
    {
        return footprintMapper.selectUmsFootprintById(id);
    }

    /**
     * 毛思淼
     * 查找userId的 id，即先确定是哪个用户，在确定此用户要查找那个id,删除操作涉及到这里
     * @param userId
     * @param id
     * @return
     */
    public UmsFootprint findById(Long userId, Long id)
    {
        //建立一个浏览足迹查询对象实体
        UmsFootprintQueryVo footprintQueryVo = new UmsFootprintQueryVo();
        //通过userId确定是哪一个用户
        footprintQueryVo.setUserId(userId);
        //查找到id
        return footprintMapper.selectUmsFootprintById(id);

    }

    /**
     * 毛思淼
     * 删除指定的id
     * @param id
     */

    public void deleteById(Long id)
    {

        footprintMapper.deleteUmsFootprintById(id);
    }

    /**毛思淼
     * 浏览足迹的添加操作
     * @param footprint
     */
    public void add(UmsFootprint footprint)
    {
        //确定添加的时间
        footprint.setAddTime(LocalDateTime.now());
        footprint.setUpdateTime(LocalDateTime.now());
        //将浏览足迹对象实体插入进去
        footprintMapper.insertUmsFootprint(footprint);
    }

}
